package com.apes.scm.masterdata.finance.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.Name;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import com.apes.scm.masterdata.party.model.PartyRole;
import com.apes.scm.masterdata.product.model.Classify;
import com.apes.scm.masterdata.product.model.Product;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

/**
 * Creator: zouyc
 * CreateDate: 2020-06-10 9:12
 * Description:
 **/
@Getter
@Setter
@SelectBeforeUpdate
@DynamicUpdate
@DynamicInsert
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name= CrossIC.CONST_TABLE_NAME)
public class CrossIC extends Model {
    public static final String CONST_TABLE_NAME = "mas_cross_ic";

    @Id
    @Column(name="id", length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "异业服务类型", padding = 4)
    @Comment("异业服务类型编码")
    private String id;

    @Column(name = "name", nullable = false)
    @Comment("异业服务类型名称")
    private String name;

    @Column(name = "cross_id")
    @Comment("异业合作类型编码")
    private String crossId;

    @Column(name = "cross_name")
    @Comment("异业合作类型名称")
    private String crossName;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "partner_id", referencedColumnName = "id", nullable = false)
    @Comment("客户")
    private PartyRole partner;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "company_id", referencedColumnName = "id", nullable = false)
    @Comment("合作公司")
    private PartyRole company;  //

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_id", referencedColumnName = "id")
    @Comment("商品")
    private Product product;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "classify_id", referencedColumnName = "id")
    @Comment("商品分类")
    private Classify classify;

    @Column(name = "price_cost_unit_in_tax", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("合作成本价")
    private double priceCostUnitInTax = 0;

    @Column(name = "account_price", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("赋能结算价")
    private double accountPrice = 0;

    @Column(name = "customer_price", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("客户支付价")
    private double customerPrice = 0;

    @Name
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "cross_pay_type", referencedColumnName = "id")
    @Comment("结算方式")
    private Enumeration crossPayType;

    @Comment("有效标记")
    @Column(name = "valid",columnDefinition = ApesConst.FIELD_BOOLEAN_TRUE)
    private boolean valid = true;
}